package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Role;
import com.example.demo.mapper.RoleMapper;
import com.example.demo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @author moguai
 * @version 1.0
 * @date 2022/3/18 16:05
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired(required = false)
    RoleMapper roleMapper;
//    @Autowired
//    User_RoleServiceImpl user_roleService;
    @Override
    public void InsertRole(Integer id, String name) {
        Role temp=new Role(id,name,System.currentTimeMillis());
        this.save(temp);
    }

    @Override
    public void UpdateRole(Integer id, String name) {
        Role temp=new Role(id,name,System.currentTimeMillis());
        this.updateById(temp);

    }

    @Override
    public void DeleteRole(Integer id) {
        roleMapper.deleteById(id);
//        user_roleService.DeleteUser_RoleByRole(id);
    }



    @Override
    public Role SelectRole(Integer id) {
        Role role=roleMapper.selectById(id);
        return role;
    }
    @Override
    public List<Role> SelectRoleByUser(List<Integer> RolesId){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("role_id",RolesId);
        List<Role> list=roleMapper.selectList(wrapper);
        return list;
    }

}
